// https://www.luogu.com.cn/problem/P1563
#include <iostream>
using namespace std;
using ll = long long;
const int maxn = 5 + 1e5;

int mov[2][2] = {-1, 1, 1, -1};  // mov[face][to]

bool face[maxn];
string name[maxn];

int main() {
    int n, m, to;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> face[i] >> name[i];

    int now = 1;
    for (int i = 1; i <= m; ++i) {
        ll dis;  // 开 ll，否则模运算计算长度时溢出
        cin >> to >> dis;
        now += mov[face[now]][to] * dis;    // 状态转移
        now = (now - 1 + n * dis) % n + 1;  // 归整到 [1, n]
    }
    cout << name[now];
}
